package com.example.demo.demo;

import com.example.demo.po.AdminRequest;

import java.util.Objects;

public class ObjectsEquals {

    /**
     * Object的hashCode()默认是返回内存地址的，但是hashCode()可以重写，所以hashCode()不能代表内存地址的不同
     * System.identityHashCode(Object)方法可以返回对象的内存地址,不管该对象的类是否重写了hashCode()方法。
     */

    private static int s3 = 666;
    private static int s4 = 666;
    private int s5 = 666;

    public static void main(String[] args) {
        double aa = 10.1;
        double bb = 10.2;
        System.out.println(Double.compare(aa, bb));

        AdminRequest adminRequest = new AdminRequest();
        System.out.println(Objects.nonNull(adminRequest));

        // ======================================================

        int s6 = 666;
        int s7 = 666;

        String s1 = "abc";
        String s2 = "abc";
        System.out.println(s1 == s2);
        System.out.println(s3 == s4);
        ObjectsEquals objectsEquals = new ObjectsEquals();
        System.out.println(s3 == objectsEquals.s5);
        System.out.println(objectsEquals.s5 == s6);
        System.out.println(s6 == s7);

        System.out.println(System.identityHashCode(s1));
        System.out.println(System.identityHashCode(s2));
        System.out.println(System.identityHashCode(s3));
        System.out.println(System.identityHashCode(s4));
        System.out.println(System.identityHashCode(objectsEquals.s5));
        System.out.println(System.identityHashCode(s6));
        System.out.println(System.identityHashCode(s7));
    }
}
